python << EOF
import vim
import string
import re
import types
import sys
sys.path.append(r'D:\Work\Tools\vim\gvim\vim73\plugin\AcpParser')
from Message.AcpMsg import *
from Message.DataString import *
from Message.HighLighter import *

#as python file can not import vim module, so create this class in vim file
class CVimHighLighter(CHighLighter):
    def __init__(self):
        pass

    def SetHlColor(self, grpName, color):
        hlCmd = ("hi def link {groupName} {hiColor}").format(groupName=grpName, hiColor=color)
        vim.command(hlCmd)

    def SetSynGroup(self, grpName, pattern):
        synCmd = ("syn match {groupName} \"\(0x\)\={pat}\" display").format(groupName=grpName, pat=pattern)
        vim.command(synCmd)


highLighter = CVimHighLighter()

EOF

function s:parse()
    "get the current current line  
python << EOF
curLine = string.upper(vim.current.line)

#create response chain
provReplyMsg = CProvReplyMsg()
provReplyMsg.SetHighLighter(highLighter)

provUpdateMsg = CProvUpdateMsg()
provUpdateMsg.SetHighLighter(highLighter)
provUpdateMsg.SetSuccessor(provReplyMsg)

rvfcMsg = CRvfcMsg()
rvfcMsg.SetHighLighter(highLighter)
rvfcMsg.SetSuccessor(provUpdateMsg)

rvfsMsg = CRvfsMsg()
rvfsMsg.SetHighLighter(highLighter)
rvfsMsg.SetSuccessor(rvfcMsg)

msg = CAcpMsg()
msg.SetSuccessor(rvfsMsg)
EOF
    "let curLine = getline('.')
    "let curLine = toupper(curLine)

    let height="50"
    silent exe "bo " . height . "split  __parser"
    setlocal buftype=nofile
    setlocal winfixheight

    execute 'nnoremap <silent> <buffer> q :close<bar>wincmd p<cr>'
    execute 'nnoremap <silent> <buffer> Q :close<bar>wincmd p<cr>'

    "the pattern match a long string which start as a number, it should be the
    "SMS message

python << EOF
m = re.search('\d\w{20,}', curLine)
buf = vim.current.buffer
if type(m) == types.NoneType:
    infoMsg = "Do not find ACP message"
    buf.append(infoMsg)
else:
    #find ACP message
    msgString = m.group()
    dataStr = CDataString(msgString)
    msg = msg.Parse(dataStr)
    msg.SetSyntaxGroup()
    dispStr = msg.FormDisplayString()
    sList = dispStr.split("\n")
    buf.append(sList)
EOF


endfunction

command ParseACP :call <SID>parse()
